package softtech.apps.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

import softtech.apps.dangtinraovat.R;
import softtech.apps.model.User;

public class UserListAdapter extends BaseAdapter {
    private static final String TAG = "FruitArrayAdapter";
	private List<User> userList = new ArrayList<User>();
	private Context mContext;
	
    static class UserViewHolder {
        ImageView userAvatar;
        TextView fullName;
    }
    public UserListAdapter(Context context, List<User> lst) {
    	mContext = context;
    	userList = lst;
    }
    @Override
	public int getCount() {
		return this.userList.size();
	}

    @Override
	public User getItem(int index) {
		return this.userList.get(index);
	}

    @Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		UserViewHolder viewHolder;
		if (row == null) {
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(R.layout.userlist_item, parent, false);
            viewHolder = new UserViewHolder();
            viewHolder.userAvatar = (ImageView) row.findViewById(R.id.userAvatarImg);
            viewHolder.fullName = (TextView) row.findViewById(R.id.fullName);
            row.setTag(viewHolder);
		} else {
            viewHolder = (UserViewHolder)row.getTag();
        }
		User user = getItem(position);
		// Set lai avatar cho user
        viewHolder.userAvatar.setImageResource(R.drawable.ic_launcher);
        viewHolder.fullName.setText(user.getFull_name());
		return row;
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
}
